# GAPXTS is xts object that contains all gaps
# GAPXTS is formed by vola::GAPExamination
fillGapsIntoVadb <- function(con, symbol, group, GAPXTS, tblname="RESEARCH_GAPS") {
  sqlcmd <- function(row) {
    sql<-sprintf("INSERT INTO `va_stratlab`.`%s` (
                  `group`,`symbol`,`date`,`direction`,`CColor`,`atr`,`AvPts`,`AARatio`)", tblname)
    sql<-paste(sql, sprintf("VALUES ('%s','%s','%s','%d',
                 '%d','%f','%f','%f')",
                 group, symbol, as.character(index(row)), row[,"GapUp"] + row[,"GapDown"]*(-1), 
                 row[,"CColor"], row[,"atr"], row[,"AvPts"], row[,"AARatio"] ))
    return(sql)
  }
  dimGAPXTS <- dim(GAPXTS)
  for (i in 1:dimGAPXTS[1]) {
    dbSendQuery(con, sqlcmd(GAPXTS[i,]))
  }
}
